package com.example.testhiber.initPackage.business.utils;

import com.alibaba.fastjson.JSONObject;
import com.example.testhiber.initPackage.business.Dictionaries.Period;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

/**
 * 工具类
 */
public class JsoupUtils {


	//登陆
	public static String login() {
		String result = "";
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("account","18251047024@qq.com");
			jsonObject.put("password","5flFngQDdz");
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/account/login");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}

	//解析登陆结果
	public static JSONObject analysisLogin(){
		String loginRes = login();
		JSONObject jsonObject = JSONObject.parseObject(loginRes);
		String dataStr = StringKit.toString(jsonObject.get("data"));
		JSONObject dataObj = JSONObject.parseObject(dataStr);
		return dataObj;
	}

	//获取标签
	public static String getTitle(String idType,String phone) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("idType", idType);//默认用手机号
			jsonObject.put("exid", phone);
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/device/mapping");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}

	//3.查询轨迹信息
	public static String getGj(String deviceId,String startTime,String endTime,String period,String trackType,
								String pageNum,String pageSize) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("deviceId", deviceId);//默认用手机号
			jsonObject.put("startTime", startTime);
			jsonObject.put("endTime", endTime);
			jsonObject.put("period", period);
			jsonObject.put("trackType", trackType);
			jsonObject.put("pageNum", pageNum);
			jsonObject.put("pageSize", pageSize);
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/device/lbstrack");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}

	//5.查询通讯录信息
	public static String getTxl(String phone) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("phone", phone);//默认用手机号
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/device/phone/postive");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}

	//6.查询通讯录信息-反向
	public static String getTxlFx(String phone) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("phone", phone);//默认用手机号
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/device/phone/negative");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = new String(document.text());

			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
			System.out.println(result);
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}
	//7.查询社交账号信息
	public static String getSjzh(String deviceId,String pageNum,String pageSize) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("deviceId", deviceId);//
			jsonObject.put("pageNum", pageNum);//
			jsonObject.put("pageSize", pageSize);//
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/device/sns");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}
	//9.提交wifi查询任务
	public static String tjWifiCx(String idType,String exid,String startTime,String endTime) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("idType", idType);//
			jsonObject.put("exid", exid);//
			jsonObject.put("startTime", startTime);//
			jsonObject.put("endTime", endTime);//
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/data/wifiSniff/add");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}
	//10.获取wifi查询任务结果
	public static String gettjWifiCxjg(String taskId) {
		String result = "";
		JSONObject json = analysisLogin();
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("taskId", taskId);//
			Connection connect = Jsoup.connect("http://jssq.ga.internal.gooapp.cn/data/wifiSniff/download");
			connect.requestBody(StringKit.toString(jsonObject));
			connect.ignoreContentType(true);
			connect.header("userId",StringKit.toString(json.get("userId")));
			connect.header("token",StringKit.toString(json.get("token")));
			connect.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36") // User-Agent of Chrome 55
					.header("Content-Type", "application/json; charset=UTF-8")
					.header("Accept", "text/plain, */*; q=0.01");
			Document document = connect.post();
			result = document.text();
			JSONObject resObject = JSONObject.parseObject(result);
			String strData = StringKit.toString(resObject.get("data"));
			result = DecryptUtil.decrypt(strData,StringKit.toString(json.get("key")));
//			JSONObject dataJson = JSONObject.parseObject(strData);
		}catch (Exception e){
			e.printStackTrace();
		}
		return  result;
	}

}
